package designpattern.demo.creational.singletonpattern;

/**
 * 多线程环境下的懒汉式单例模式(DCL，双检锁+volatile实现)
 * 加入了volatile变量来禁止指令重排序
 * @author ywq
 *
 *
 */

public class SingleLazy4 {

    private static volatile SingleLazy4 s = null;

    private SingleLazy4() {
    }

    public static SingleLazy4 getInstance() {
        if (s==null) {
            synchronized (SingleLazy4.class) {
                if (s==null)
                    //--->A;
                    s = new SingleLazy4();
            }
        }
        return s;

    }


}
